package com.pgytesting.secondhandcar.controller.mcpcar;

import com.pgytesting.secondhandcar.model.Pagination;
import com.pgytesting.secondhandcar.model.SalesCommissionSettlement;
import com.pgytesting.secondhandcar.service.OrderNameService;
import com.pgytesting.secondhandcar.service.SalesCommissionSettlementService;
import com.pgytesting.secondhandcar.vo.ResponseMessage;
import javafx.scene.shape.VLineTo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author : frosty0804@gmail.com
 * @version : v1.0
 * @projectName : secondhandcar
 * @className : OrderController
 * @description : TODO(一句话描述该类的功能)
 * @date : 2019/8/20 15:32
 */
@Slf4j
@RestController
@RequestMapping("/sales/order")
public class OrderController {

    @Autowired
    OrderNameService orderNameService;

    @Autowired
    SalesCommissionSettlementService salesCommissionSettlementService;


    /**
     * 查询所有订单
     *
     * @param pagination
     * @param bindingResult
     * @return
     */
    @RequestMapping(value = "/getOrder", method = RequestMethod.POST)
    public ResponseMessage getOrder(@Valid @RequestBody Pagination pagination, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            String msg = bindingResult.getFieldError().getDefaultMessage();
            return ResponseMessage.errorResponse(msg);
        }
        return orderNameService.queryAllByLimit(pagination);
    }

    /**
     * 查询订单信息
     *
     * @param orderId 订单ID
     * @return
     */
    @RequestMapping(value = "/getOrderList", method = RequestMethod.POST)
    public ResponseMessage getOrderList(@RequestBody Map<String, List<String>> orderId) {
                try {
                    return orderNameService.queryUseOrder(orderId.get("orderId"));
//            return orderNameService.queryUserAll(pagination);
        } catch (Exception e) {
            log.error("服务异常", e);
            return ResponseMessage.errorResponse("服务异常");
        }
    }

    /**
     * 销售查询订单收益
     *
     * @return
     */
    @RequestMapping(value = "/getOrderIncome", method = RequestMethod.GET)
    public ResponseMessage getOrderIncome() {
        try {
            return salesCommissionSettlementService.selectAll();
        } catch (Exception e) {
            log.error("服务异常", e);
            return ResponseMessage.errorResponse("服务异常");
        }
    }

}
